const arr = [1, 2, [3, 4], [5, 6, 7, [8, 9]]];
//  => [1,2,3,4,5,6,7,8,9,10];
function flat(args) {
    let result = []
    args.map( item => {
        if (Array.isArray(item)) {
            result = result.concat(flat(item));
        } else {
            result.push(item);
        }
    })
    return result;
}

function flat1(args) {
    const isDeepArr = args.some(item => item instanceof Array);
    if (!isDeepArr) {
        return args;
    }
    const res =  Array.prototype.concat.apply([], arr)
    return flat1(res);
}

console.log(flat(arr));